﻿using System;
using System.Collections.Generic;
using System.Text;
using Jargon.Resources;
using System.Web;

namespace Jargon.Web.Controls
{
    public class JargonTextReader
    {
        /// <summary>
        /// Gets or sets the current jargon in the web context
        /// </summary>
        public static string CurrentJargon
        {
            get
            {
                if (HttpContext.Current.Session["Jargon.Current"] != null)
                {
                    return HttpContext.Current.Session["Jargon.Current"].ToString();
                }
                else
                {
                    return string.Empty;
                }
            }
            set
            {
                HttpContext.Current.Session["Jargon.Current"] = value;
            }
        }

        /// <summary>
        /// Retrieves a string from one the Jargons that user requested with standard letter case
        /// (as written in the resource file)
        /// </summary>
        /// <param name="key">The JargonKey of the text</param>
        /// <returns>JargonText for the key</returns>
        /// <remarks>The Jargons that user requested are acquired via browser settings of the user</remarks>
        public static string GetString(string key)
        {
            return GetString(key, JargonLetterCase.Standard);
        }

        /// <summary>
        /// Retrieves a string from one the Jargons that user requested
        /// </summary>
        /// <param name="key">The JargonKey of the text</param>,
        /// <param name="letterCase">The letter case of the text to be retrieved</param>
        /// <returns>JargonText for the key</returns>
        /// <remarks>The Jargons that user requested are acquired via browser settings of the user</remarks>
        public static string GetString(string key, JargonLetterCase letterCase)
        {
            string str = string.Empty;
            if (string.IsNullOrEmpty(CurrentJargon))
            {
                string[] userLanguages = HttpContext.Current.Request.UserLanguages;
                str = JargonReader.GetString(userLanguages, key, letterCase);
            }
            else
            {
                str = JargonReader.GetString(CurrentJargon, key, letterCase);
            }
            return str;
        }

        /// <summary>
        /// Retrieves a string from the Jargon requested
        /// </summary>
        /// <param name="key">The JargonKey of the text</param>
        /// <param name="letterCase">The letter case of the text to be retrieved</param>
        /// <param name="language">The language code of the Jargon requested</param>
        /// <returns>JargonText for the key</returns>
        public static string GetString(string key, JargonLetterCase letterCase, string language)
        {
            return JargonReader.GetString(language, key, letterCase);
        }
    }
}
